import { ref } from 'vue'
import type { TreeNodeData } from '@arco-design/web-vue'
import { listCategory } from '@/apis/system/api'

/** 部门模块 */
export function useApiCategory(options?: { onSuccess?: () => void }) {
  const loading = ref(false)
  const categoryList = ref<TreeNodeData[]>([])

  const getCategoryTree = async () => {
    try {
      loading.value = true
      const res = await listCategory()
      categoryList.value = res.data
      options?.onSuccess && options.onSuccess()
    } finally {
      loading.value = false
    }
  }
  return { categoryList, getCategoryTree, loading }
}
